<!-- 擒龙形态 -->
<template>
  <div class="wrap" id="app">
    <div class="tag flex column">
      <div
        class="item"
        v-for="(item, index) in columns"
        :key="item.cId"
        :class="{ cur: cId == item.cId }"
        @click="tag(index)"
      ></div>
    </div>
  </div>
</template>
<script>
import { getColumn, getStrategyStockPoolList } from "../api/api";

import dayjs from "dayjs";
export default {
  data() {
    return {
      columns: [],
      cId: "",
      productColumnId: location.href.indexOf("test") > -1 ? 80 : 55,
      imgSrc: "",
      categoryProfile: "",
    };
  },
  mounted() {
    document.title = "财报掘金";
    this.getColumn();
  },

  methods: {
    async getColumn() {
      await getColumn({
        productColumnId: this.productColumnId,
      }).then((back) => {
        if (back.status == 1) {
          let data = back.data;
          this.columns = data.filter((item) => {
            return (
              item.categoryName == "飞天龙（预增）" ||
              item.categoryName == "发财龙（高送转）" ||
              item.categoryName == "报喜龙（公告变更）" ||
              item.categoryName == "抬头龙（次新股）"
            );
          });
          this.tag(0);
        }
      });
    },
    blockStock(data) {
      const { stock, cId, productId, productColumnId } = data;
      window.prompt(
        "",
        `up://["user.info",${Date.now()},{"type":"财报掘金","params":{"cId":${cId},"productId":${productId},"productColumnId":${productColumnId}},"data":{"stock":${stock}}}]`
      );
    },
    async tag(type = 0) {
      this.cId = this.columns[type].cId;
      this.productColumnId = this.columns[type].productColumnId;
      this.getStockList();
    },
    async getStockList() {
      const { productId, token } = this.$route.params;
      const params = {
        cId: this.cId,
        productId,
        productColumnId: this.productColumnId,
        clientCentralToken: token,
      };
      await getStrategyStockPoolList(params).then((back) => {
        if (back.status == 1) {
          let data = back.data;
          const stock = data.map((item) => ({
            id: item.id,
            stockCode: item.stockCode,
            blockName: item.themeName,
            subjectNature: item.themeType,
            date: dayjs(item.createTime).format("YYYY-MM-DD"),
            publishTime: dayjs(item.publishTime || Date.now()).format(
              "YYYY-MM-DD"
            ),
            teachingSeries: item.teachingSeries,
          }));
          this.blockStock({
            cId: this.cId,
            productId,
            productColumnId: this.productColumnId,
            stock: JSON.stringify(stock),
          });
        }
      });
    },
  },
};
</script>
<style lang="scss" scoped>
.wrap {
  width: 539px;
  padding: 0 20px 20px;
  box-sizing: border-box;
  border: 1px solid #313337;
  .tag {
    align-items: center;
    width: 100%;
    .item {
      cursor: pointer;
      width: 499px;
      height: 100px;
      margin-top: 20px;
      &:nth-child(1) {
        background: url($PIC_URL + "/tlbypcWeb/tagColumn/feitianlong_nor.png")
          no-repeat center;
        &.cur {
          background: url($PIC_URL + "/tlbypcWeb/tagColumn/feitian_sel.png")
            no-repeat center;
        }
      }
      &:nth-child(2) {
        background: url($PIC_URL + "/tlbypcWeb/tagColumn/facailong_nor.png")
          no-repeat center;
        &.cur {
          background: url($PIC_URL + "/tlbypcWeb/tagColumn/facai_sel.png")
            no-repeat center;
        }
      }
      &:nth-child(3) {
        background: url($PIC_URL + "/tlbypcWeb/tagColumn/baoxi_nor.png")
          no-repeat center;
        &.cur {
          background: url($PIC_URL + "/tlbypcWeb/tagColumn/baoxi_sel.png")
            no-repeat center;
        }
      }
      &:nth-child(4) {
        background: url($PIC_URL + "/tlbypcWeb/tagColumn/taitou_nor.png")
          no-repeat center;
        &.cur {
          background: url($PIC_URL + "/tlbypcWeb/tagColumn/taitou_sel.png")
            no-repeat center;
        }
      }
    }
  }
}
</style>
